//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    this.getSign();
    this.getUserInfo();
  },
  getSign: function () {
    var signStorage = wx.getStorageSync('sign');
    if (!signStorage) {
      wx.login({
        success: res => {
          if (res.code) {
            wx.request({
              url: 'https://ydnshop.hepulanerp.com/index.php/Weshop/SApi/index/key/2sdfdd332342341dddff46e189670/m/actionAuth/wid/39',
              data: {
                code: res.code,

              },
              success: res => {
                wx.setStorageSync('sign', res.data.sign)
              },
              fail: res => {
                console.log(res)
              }
            })
          }
        }
      })
    }
    else {
      this.globalData.sign = signStorage;
    }
  },
  getUserInfo: function () {
    var userInfoStorage = wx.getStorageSync('user');
    if (!userInfoStorage) {
      var that = this;
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              console.log(res);
              that.globalData.userInfo = res.userInfo
              wx.setStorageSync('user', res.userInfo)
            },
            fail: function (res) {
              console.log(res);
            }
          })
        }
      })
    }
    else {
      this.globalData.userInfo = userInfoStorage;
    }
  },
  globalData: {
    sign: "",
    userInfo: null,
    ydnBase: "https://ydnshop.hepulanerp.com",
  }
})